package cn.t.facade.device;


import cn.t.converter.device.FaultDTOConverter;
import cn.t.core.facade.FacadeImpl;
import cn.t.dto.android.DeviceFaultDTO;
import cn.t.dto.device.FaultDTO;
import cn.t.enums.FaultEnum;
import cn.t.model.device.FaultDO;
import cn.t.service.device.FaultService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 设备报警信息表(日志)(Fault)服务编排
 *
 * @author t
 * @since 2024-05-24 10:19:34
 */
@Slf4j
@Service
@AllArgsConstructor
public class FaultFacade extends FacadeImpl<FaultDTO, FaultDO, FaultDTOConverter, FaultService> {

    @Transactional
    public Boolean add(DeviceFaultDTO req) {
        if (StringUtils.isBlank(req.getContent()) && StringUtils.isNotBlank(req.getFaultCode())) {
            req.setContent(FaultEnum.getName(req.getFaultCode()).getName());
        }
        FaultDO faultDO = converter.dto2Model(req);
        service.add(faultDO);
        return true;
    }
}

